<?php

class Exts_Controller_SecureAction extends Exts_Controller_Action {

	public function init() {

		parent::init();

		if (!$this->_auth->hasIdentity()) {
			$this->_session->user->auth = false;
			return $this->_redirect('/user/login/');
		}

		$this->_session->user->auth = true;
		$this->_user = $this->_session->user;

		/**
		 * Acl
		 */
		if (!is_array($this->_user->resources)) {
			return $this->_redirect('/user/login/');
		}

		if (!in_array($this->_getParam('controller'), $this->_user->resources)) {
			return $this->_redirect('/user/permissiondenied/');
		}

		$valid = $this->_user->acl->isAllowed(
				$this->_user->role, $this->_getParam('controller'), $this->_getParam('action')
		);

		if (!$valid) {
			return $this->_redirect('/user/permissiondenied/');
		}

		$this->view->username = $this->_user->username;

		
	}

}
